FROM node:14.3.0-buster-slim

RUN set -eux; \
    savedAptMark="$(apt-mark showmanual)"; \
    apt-get update; \
    apt-get install -y --no-install-recommends ca-certificates netcat; \
    groupadd -r -g 999 app && useradd -r -g app -u 999 app; \
    mkdir -p /home/app; \
    mkdir -p /home/app/{bin,lib}; \
    chown app /home/app;

WORKDIR /home/app

# only install production deps to keep image small
COPY package.json /home/app
RUN npm install --production

COPY index.js /home/app
COPY bin/ /home/app/bin
COPY lib/ /home/app/lib
COPY docker-entrypoint.sh /usr/local/bin/

RUN chown app:app -R /home/app; \
    chmod 777 /tmp;

# env 
ENV DATABASE_HOST 127.0.0.1
ENV DATABASE_USER root
ENV DATABASE_PASSWORD password
ENV DATABASE_NAME sakila
ENV DATABASE_PORT 3306

EXPOSE 3000
ENTRYPOINT ["docker-entrypoint.sh"]
#CMD ["sh", "-c", "node index.js -h $DATABASE_HOST -p $DATABASE_PASSWORD -d $DATABASE_NAME -u $DATABASE_USER -o $DATABASE_PORT -n 3000 -r 0.0.0.0"]
